package org.example.msg.utils;

import com.zhenzi.sms.ZhenziSmsClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class SmsUtils {


    @Autowired
    ZhenziSmsClient zhenziSmsClient;

    @Bean
    public ZhenziSmsClient initBean(){
        return new ZhenziSmsClient(SmsUtils.APIURL, SmsUtils.APPID, SmsUtils.APPSECRET);
    }

    //apiUrl为请求地址，个人开发者使用https://sms_developer.zhenzikj.com，企业开发者使用https://sms.zhenzikj.com
    public static String APIURL = "https://sms_developer.zhenzikj.com";

    public static String APPID = "111291";
    public static String APPSECRET = "31e59205-bd96-412c-aed4-3d50824ed27f";
    public static String TEMPLATEID = "8770";
    public static String TEMPLATEID1 = "10303";
    public static String TEMPLATEID2 = "8770";


   public  void send(String phone,String content) throws Exception {
       Map<String,Object> params=new HashMap<>();
       params.put("number",phone);
       // 修改为自己的templateId
       params.put("templateId", SmsUtils.TEMPLATEID);
       String[] templateParams = new String[2];
       templateParams[0] = content;
       templateParams[1] = "2分钟";
       params.put("templateParams", templateParams);
       zhenziSmsClient.send(params);
   }

}
